package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.mapper.AlbumStatMapper;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <a href="https://www.shallowrecall.top/">Recall`Blog</a></br>
 * <a href="https://github.com/ShallowRecall">GitHub</a>
 *
 * @author Recall
 * @createTime 2025/03/17 22:11
 **/
@RestController
@RequestMapping("/rpc/inner/albuminfo")
public class AlbumInfoRpcController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private TrackInfoService trackInfoService;


    @GetMapping("/getAlbumInfoAndAttrValue/{albumId}")
    @Operation(summary = "获取专辑信息")
    Result<AlbumInfo> getAlbumInfoAndAttrValue(@PathVariable Long albumId) {
        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
        return Result.ok(albumInfo);
    }

    @GetMapping("/getAlbumCategory/{albumId}")
    @Operation(summary = "获取专辑分类")
    Result<BaseCategoryView> getAlbumCategory(@PathVariable Long albumId) {
        BaseCategoryView baseCategoryView = baseCategoryService.getAlbumCategory(albumId);
        return Result.ok(baseCategoryView);
    }

    @GetMapping("/getAlbumStat/{albumId}")
    @Operation(summary = "获取专辑统计信息")
    Result<AlbumStatVo> getAlbumStat(@PathVariable(name = "albumId") Long albumId) {
        AlbumStatVo albumStatVo = albumInfoService.getAlbumStat(albumId);
        return Result.ok(albumStatVo);
    }

    @GetMapping("/getBaseCategory3ListByC1Id/{c1Id}")
    @Operation(summary = "获取一级分类下的三级分类")
    Result<List<BaseCategory3>> getBaseCategory3ListByC1Id(@PathVariable(name = "c1Id") Long c1Id) {
        List<BaseCategory3> baseCategory3ListByC1Id = baseCategoryService.findTopBaseCategory3(c1Id);
        return Result.ok(baseCategory3ListByC1Id);
    }

    @GetMapping("/getAllCategory1Id")
    @Operation(summary = "获取所有一级分类")
    Result<List<Long>> getAllCategory1Id() {
        List<Long> allCategory1Id = baseCategoryService.getAllCategory1Id();
        return Result.ok(allCategory1Id);
    }

    @PostMapping("/getTrackList")
    @Operation(summary = "根据声音id列表获取声音集合")
    Result<List<TrackListVo>> getTrackList(@RequestBody List<Long> trackIdList) {
        List<TrackListVo> trackListVos = albumInfoService.getTrackList(trackIdList);
        return Result.ok(trackListVos);
    }

    @GetMapping("/getAlbumInfoIdList")
    @Operation(summary = "获取所有专辑id列表")
    Result<List<Long>> getAlbumInfoIdList() {
        List<Long> albumInfoIdList = albumInfoService.getAlbumInfoIdList();
        return Result.ok(albumInfoIdList);
    }

    @GetMapping("/getTrackListByCurrentTrackId/{userId}/{trackId}/{trackCount}")
    Result<List<TrackInfo>> getTrackListByCurrentTrackId(@PathVariable(name = "userId") Long userId,
                                                         @PathVariable(name = "trackId") Long trackId,
                                                         @PathVariable(name = "trackCount") Integer trackCount) {
        List<TrackInfo> trackListByCurrentTrackId = trackInfoService.getTrackListByCurrentTrackId(userId, trackId, trackCount);
        return Result.ok(trackListByCurrentTrackId);
    }

    @GetMapping("/getTrackInfoByTrackId/{trackId}")
    Result<TrackInfo> getTrackInfoByTrackId(@PathVariable(name = "trackId") Long trackId) {
        TrackInfo trackInfo = trackInfoService.getById(trackId);
        return Result.ok(trackInfo);
    }

    @GetMapping("/getAlbumInfoByTrackId/{trackId}")
    Result<AlbumInfo> getAlbumInfoByTrackId(@PathVariable(name = "trackId") Long trackId){
        AlbumInfo albumInfo = albumInfoService.getAlbumInfoByTrackId(trackId);
        return Result.ok(albumInfo);
    }

}
